home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "rawfmt.h"
-
- RawToSCMI(HFileInfo *hp, raw_t *img)
- {
- long n;
- int i, err;
- uchar *p, *p2, *buf;
- int refNum;
-
- /* create and open file */
- if ((err=HCreate(hp->ioVRefNum, hp->ioDirID, hp->ioNamePtr, '????', 'SCMI')) != noErr) {
- PtoCstr((char *)hp->ioNamePtr);
- if (err == dupFNErr)
- fprintf(stderr," %s: RawToSCMI: File already exists\n",hp->ioNamePtr);
- else
- fprintf(stderr," %s: RawToSCMI: Create err = %d\n",hp->ioNamePtr,err);
- return;
- }
-
- if ((err=HOpen(hp->ioVRefNum, hp->ioDirID, hp->ioNamePtr, fsRdWrPerm, &refNum)) != noErr) {
- PtoCstr((char *)hp->ioNamePtr);
- fprintf(stderr,"%s: RawToSCMI: HOpen err = %d\n",hp->ioNamePtr,err);
- return;
- }
-
- p = buf = (uchar *)NewPtr(1024L);
-
- sprintf((char *)p,"SCMI%4u",1); /* version */
- p += 8;
- sprintf((char *)p,"AT%8lu%4u%4u%4u",12L,img->width,img->height,img->ncolors);
- p += 22;
- sprintf((char *)p,"CM%8lu",img->ncolors*3L);
- p += 10;
-
- p2 = (uchar *)img->cmap;
- for (i=0; i<img->ncolors*3; i++)
- *p++ = *p2++;
-
- /* Pixel Data */
- sprintf((char *)p,"PD%8lu",(long)img->width * (long)img->height);
- p += 10;
-
- n = p-buf;
- if ((err=FSWrite(refNum, &n, buf)) == noErr) {
- n = (long)img->width * (long)img->height;
- err=FSWrite(refNum, &n, img->data);
- }
- if (err) {
- PtoCstr((char *)hp->ioNamePtr);
- fprintf(stderr," %s: RawToSCMI: FSWrite err = %d\n",hp->ioNamePtr,err);
- }
- DisposPtr(buf);
-
- FSClose(refNum);
- }
-
-
-